#ifndef CACHEMONITOR_H
#define CACHEMONITOR_H

#include "router/systemMonitor/cacheMonitor/cmddlg.h"
#include <QObject>
#include <Utils.h>
#include <ui_index.h>
#include <QObject>
#include <api/systemMonitor/cachelistapi.h>
#include <QtCharts>

struct SliceInfo{
    int     m_value;        // 数值
    QString m_labelName;    // label 标签
    QColor  m_color;        // 颜色

    SliceInfo(int value, QString name, QColor color) {
    // SliceInfo(int value, QString name) {
        m_value = value;
        m_labelName = name;
        m_color = color;
    }
};

class CacheMonitor : public QObject
{
    Q_OBJECT
public:
    explicit CacheMonitor(Ui::Index *ui,QObject *parent = nullptr);

protected:
    // bool eventFilter(QObject *obj, QEvent *event) override;

signals:

private:
    Ui::Index *ui;
    Utils utils;
    CacheListApi api;
    QJsonArray commandStats;
    QJsonObject info;
    int dbSize;
    int cmdSum = 0;
    CmdDlg *dlg;
    QPieSeries *pieSeries;

    void init();
    void getCache();
    void initBaseInfo();
    void initCmdStatisticsView();
    QList<QPieSlice*> sortPie(QList<SliceInfo> &slicesInfo);
    int  randomColor();
};

#endif // CACHEMONITOR_H
